﻿using System;
using System.Collections.Generic;

namespace Microsoft.Xna.Framework.Media
{
	/// <summary>
	/// A collection of songs in the song library.
	/// </summary>
	public sealed class SongCollection : IEnumerable<Song>, IDisposable
	{
		private List<Song> collection = new List<Song>();

		#region Properties
		/// <summary>
		/// Gets the number of Song objects in the SongCollection.
		/// </summary>
		public int Count
		{
			get
			{
				if (IsDisposed)
				{
					throw new ObjectDisposedException(this.GetType().Name);
				}
				return collection.Count;
			}
		}

		/// <summary>
		/// Gets a value indicating whether the object is disposed.
		/// </summary>
		public bool IsDisposed
		{
			get { return collection == null; }
		}

		/// <summary>
		/// Gets the Song at the specified index in the SongCollection.
		/// </summary>
		/// <param name="index"></param>
		public Song this[int index]
		{
			get
			{
				if (IsDisposed)
				{
					throw new ObjectDisposedException(this.GetType().Name);
				}
				return collection[index];
			}
		}
		#endregion

		#region Private Methods
		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
		{
			return collection.GetEnumerator();
		}
		#endregion

		#region Public Methods
		/// <summary>
		/// Immediately releases the unmanaged resources used by this object.
		/// </summary>
		public void Dispose()
		{
			collection = null;
		}

		/// <summary>
		/// Returns an enumerator that iterates through the SongCollection.
		/// </summary>
		public IEnumerator<Song> GetEnumerator()
		{
			if (IsDisposed)
			{
				throw new ObjectDisposedException(this.GetType().Name);
			}
			return collection.GetEnumerator();
		}
		#endregion
	}
}
